package com.example.demo;

import lombok.Data;
import org.hibernate.annotations.Proxy;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * author 陈伯瑞
 * date 2020/5/17 0017 18:59
 * version 1.0
 **/
@Entity
@Table(name = "userinfo")
@Data
@Proxy(lazy = false)
public  class UserInfo implements UserDetails {
    /**
     *
     */
    @Id
    private String username;
    private String password;
    private String role;

    public UserInfo() {
    }

    public UserInfo(String username, String password,String role) {
        this.username = username;
        this.password = password;
        this.role=role;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<SimpleGrantedAuthority> authorities = new ArrayList<>();
        authorities.add(new SimpleGrantedAuthority(role));
        return authorities;

    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}

